<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>全部帖子</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="lib/layui/css/layui.css" media="all">
	<link rel="stylesheet" href="css/admin.css" media="all">

</head>
<body>
<div class="layui-fluid">
	<div class="layui-col-md12">
		<div class="layui-navs">
					<span class="layui-breadcrumb" lay-separator="—">
						<a href="javascript:;">系统设置</a>
						<a href="javascript:;">管理员设置</a>
						<a><cite>待审核帖子</cite></a>
					</span>
			<a class="layui-btn layui-btn-small" style="line-height:1.6em;float:right;height: 36px;" href="javascript:location.replace(location.href);" title="刷新">
				<i class="layui-icon layui-icon-refresh" style="line-height:36px;font-size: 16px;"></i>
			</a>
		</div>
	</div>
	<div class="layui-col-md12">
		<div class="layui-card">
			<div class="layui-card-body ">
				<form class="layui-form layui-col-space5" action="javascript:void(0);">
					<!--<div class="layui-inline layui-show-xs-block">-->
					<!--<input type="text" name="start_time" id="start_time" value="" placeholder="请选择开始时间" autocomplete="off" class="layui-input">-->
					<!--</div>-->
					<!--<div class="layui-inline layui-show-xs-block">-->
					<!--<input type="text" name="end_time" id="end_time" value="" placeholder="请选择结束时间" autocomplete="off" class="layui-input">-->
					<!--</div>-->
					<div class="layui-inline layui-show-xs-block">
						<input type="text" name="name" value="" id="input1"  placeholder="请输入想搜索的帖子" autocomplete="off" class="layui-input" style="width: 300px">
					</div>
					<div class="layui-inline layui-show-xs-block">
						<button class="layui-btn"  lay-submit="javascript:void(0);" lay-filter="javascript:void(0);" onclick="serach()"><i class="layui-icon">&#xe615;</i></button>
					</div>
				</form>
			</div>
			<script>
				// 模糊根据帖子名搜索的实现
				function serach() {
					var info = $('#input1').val()
					$.ajax({
						url:"/forum/post/selectByPostTestName?postName=" + info,
						type:"post",
						dataType:"json",
						success:function (data) {
							var html = "";
							for (var i = 0; i < data.length; i++){
								html = html + "<tr><td>" + (i+1);
								html = html + "</td><td>" + data[i].postName;
								html = html + "</td><td>" + data[i].userName;
								html = html + "</td><td>" + data[i].postType;
								html = html + "</td><td>" + data[i].postTime;
								html = html + "</td><td><a class=\"layui-btn layui-btn-sm layui-btn-normal\" title=\"编辑\" onclick=\"execute_open('编辑角色', 'role_operation2.html?id=" + data[i].postId + "', 800, 500)\" href=\"javascript:;\"><i class=\"layui-icon layui-icon-edit\"></i>详情</a>"
                                html = html + "<a class=\"layui-btn layui-btn-sm layui-btn-normal\" title=\"编辑\" onclick=\"pass(" + data[i].postId + ")\" href=\"javascript:;\"><i class=\"layui-icon layui-icon-edit\"></i>通过</a>"
                                html = html + "<a class=\"layui-btn layui-btn-sm layui-btn-danger\" title=\"删除\" onclick=\"deleteBy(" + data[i].postId + ")\" href=\"javascript:;\"><i class=\"layui-icon layui-icon-delete\"></i>删除</a>"
								html = html + "</td></tr>";
							}
							console.log(html)
							$('#tbody').html(html)
						}
					})
				}
			</script>
			<!--<div class="layui-card-header">-->
			<!--<button class="layui-btn" onclick="execute_open('添加角色', 'role_operation.html', '1000', '800')"><i class="layui-icon"></i>添加角色</button>-->
			<!--</div>-->
			<div class="layui-card-header">
				<button class="layui-btn" onclick="time()"><i class="layui-icon"></i>最近时间</button>
			</div>
			<div class="layui-card-body">
				<table class="layui-table layui-form">
					<thead>
					<tr>
						<th>序号</th>
						<th>帖子名</th>
						<th>用户名</th>
						<th>帖子类型</th>
						<th>发帖时间</th>
						<th>管理</th>
					</tr>
					</thead>
					<tbody id="tbody">
					<!--<tr>-->
					<!--<td>1</td>-->
					<!--<td>1</td>-->
					<!--<td>超级管理员</td>-->
					<!--<td>10</td>-->
					<!--<td>3</td>-->
					<!--<td>-->
					<!--<a class="layui-btn layui-btn-sm layui-btn-normal" title="编辑" onclick="execute_open('编辑角色', 'role_operation.html?id=1', 1000, 800)" href="javascript:;"><i class="layui-icon layui-icon-edit"></i>详情</a>-->
					<!--<a class="layui-btn layui-btn-sm layui-btn-danger" title="删除" onclick="execute_del(this, 1, '')" href="javascript:;"><i class="layui-icon layui-icon-delete"></i>删除</a>-->
					<!--</td>-->
					<!--</tr>-->
					</tbody>
				</table>
			</div>
			<div class="page" style="text-align: center">
				<ul class="pagination">
					<!--<li class="disabled"><span>上一页</span></li> -->
					<!--<li class="active"><span>1</span></li>-->
					<!--<li><a href="javascript:;">2</a></li>-->
					<!--<li><a href="javascript:;">3</a></li>-->
					<!--<li><a href="javascript:;">4</a></li> -->
					<!--<li><a href="javascript:;">下一页</a></li>-->
				</ul>
			</div>
		</div>
	</div>
</div>
</body>


<script src="../jquery/jquery-3.4.1.js"></script>
<script>
	$.ajax({
		url:"/forum/post/selectAllPostTest",
		type:"post",
		dataType:"json",
		success:function (data) {
			var html = "";
			for (var i = 0; i < data.length; i++){
				html = html + "<tr><td>" + (i+1);
				html = html + "</td><td>" + data[i].postName;
				html = html + "</td><td>" + data[i].userName;
				html = html + "</td><td>" + data[i].postType;
				html = html + "</td><td>" + data[i].postTime;
				html = html + "</td><td><a class=\"layui-btn layui-btn-sm layui-btn-normal\" title=\"编辑\" onclick=\"execute_open('编辑角色', 'role_operation2.html?id=" + data[i].postId + "', 800, 500)\" href=\"javascript:;\"><i class=\"layui-icon layui-icon-edit\"></i>详情</a>"
				html = html + "<a class=\"layui-btn layui-btn-sm layui-btn-normal\" title=\"编辑\" onclick=\"pass(" + data[i].postId + ")\" href=\"javascript:;\"><i class=\"layui-icon layui-icon-edit\"></i>通过</a>"
				html = html + "<a class=\"layui-btn layui-btn-sm layui-btn-danger\" title=\"删除\" onclick=\"deleteBy(" + data[i].postId + ")\" href=\"javascript:;\"><i class=\"layui-icon layui-icon-delete\"></i>删除</a>"
				html = html + "</td></tr>";
			}
			console.log(html)
			$('#tbody').html(html)
		}
	})


    function pass(info) {
        var parmeter = "postId=" + info;
        $.ajax({
            url:"/forum/post/passPostTest",
            data: parmeter,
            type:"post",
            success:function (data) {
                alert(data);
                location.replace(location.href);
                // if (data == "success"){
                //     alert("删除成功")
                // } else {
                //     alert("删除失败")
                // }
            }
        })
    }

	function deleteBy(info) {
		// var role = $('input[name="role"]:checked').val()
		// // 如果使用的是表单，直接进行表单序列化即可
		// var parmeter = "user=" + user + "&pwd=" + pwd + "&role=" + role
		var parmeter = "postId=" + info;
		$.ajax({
			url:"/forum/post/deleteByPostTestId",
			data: parmeter,
			type:"post",
			success:function (data) {
				if (data == "success"){
					alert("删除成功")
				} else {
					alert("删除失败")
				}
                location.replace(location.href);
            }
		})

	}
</script>
<script>
	// 根据时间进行排序
	function time() {
		var a = $('td')
		alert(a)
		var test = a[0]
		alert(test)
	}
</script>
</html>

<script src="js/jquery-3.4.1.min.js"></script>
<script src="lib/layui/layui.js"></script>
<script src="js/admin.js"></script>